home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / glib-2.0 / glib / ghook.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-04-25  |  5.7 KB  |  179 lines

  1. /* GLIB - Library of useful routines for C programming
  2.  * Copyright (C) 1995-1997  Peter Mattis, Spencer Kimball and Josh MacDonald
  3.  *
  4.  * This library is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU Lesser General Public
  6.  * License as published by the Free Software Foundation; either
  7.  * version 2 of the License, or (at your option) any later version.
  8.  *
  9.  * This library is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the GNU
  12.  * Lesser General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU Lesser General Public
  15.  * License along with this library; if not, write to the
  16.  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  17.  * Boston, MA 02111-1307, USA.
  18.  */
  19.  
  20. /*
  21.  * Modified by the GLib Team and others 1997-2000.  See the AUTHORS
  22.  * file for a list of people on the GLib Team.  See the ChangeLog
  23.  * files for a list of changes.  These files are distributed with
  24.  * GLib at ftp://ftp.gtk.org/pub/gtk/. 
  25.  */
  26.  
  27. #ifndef __G_HOOK_H__
  28. #define __G_HOOK_H__
  29.  
  30. #include <glib/gmem.h>
  31.  
  32. G_BEGIN_DECLS
  33.  
  34.  
  35. /* --- typedefs --- */
  36. typedef struct _GHook        GHook;
  37. typedef struct _GHookList    GHookList;
  38.  
  39. typedef gint        (*GHookCompareFunc)    (GHook        *new_hook,
  40.                          GHook        *sibling);
  41. typedef gboolean    (*GHookFindFunc)    (GHook        *hook,
  42.                          gpointer     data);
  43. typedef void        (*GHookMarshaller)    (GHook        *hook,
  44.                          gpointer     marshal_data);
  45. typedef gboolean    (*GHookCheckMarshaller)    (GHook        *hook,
  46.                          gpointer     marshal_data);
  47. typedef void        (*GHookFunc)        (gpointer     data);
  48. typedef gboolean    (*GHookCheckFunc)    (gpointer     data);
  49. typedef void        (*GHookFinalizeFunc)    (GHookList      *hook_list,
  50.                          GHook          *hook);
  51. typedef enum
  52. {
  53.   G_HOOK_FLAG_ACTIVE        = 1 << 0,
  54.   G_HOOK_FLAG_IN_CALL        = 1 << 1,
  55.   G_HOOK_FLAG_MASK        = 0x0f
  56. } GHookFlagMask;
  57. #define G_HOOK_FLAG_USER_SHIFT    (4)
  58.  
  59.  
  60. /* --- structures --- */
  61. struct _GHookList
  62. {
  63.   gulong        seq_id;
  64.   guint            hook_size : 16;
  65.   guint            is_setup : 1;
  66.   GHook           *hooks;
  67.   GMemChunk       *hook_memchunk;
  68.   GHookFinalizeFunc finalize_hook;
  69.   gpointer        dummy[2];
  70. };
  71. struct _GHook
  72. {
  73.   gpointer     data;
  74.   GHook        *next;
  75.   GHook        *prev;
  76.   guint         ref_count;
  77.   gulong     hook_id;
  78.   guint         flags;
  79.   gpointer     func;
  80.   GDestroyNotify destroy;
  81. };
  82.  
  83.  
  84. /* --- macros --- */
  85. #define    G_HOOK(hook)            ((GHook*) (hook))
  86. #define    G_HOOK_FLAGS(hook)        (G_HOOK (hook)->flags)
  87. #define    G_HOOK_ACTIVE(hook)        ((G_HOOK_FLAGS (hook) & \
  88.                       G_HOOK_FLAG_ACTIVE) != 0)
  89. #define    G_HOOK_IN_CALL(hook)        ((G_HOOK_FLAGS (hook) & \
  90.                       G_HOOK_FLAG_IN_CALL) != 0)
  91. #define G_HOOK_IS_VALID(hook)        (G_HOOK (hook)->hook_id != 0 && \
  92.                      (G_HOOK_FLAGS (hook) & \
  93.                                           G_HOOK_FLAG_ACTIVE))
  94. #define G_HOOK_IS_UNLINKED(hook)    (G_HOOK (hook)->next == NULL && \
  95.                      G_HOOK (hook)->prev == NULL && \
  96.                      G_HOOK (hook)->hook_id == 0 && \
  97.                      G_HOOK (hook)->ref_count == 0)
  98.  
  99.  
  100. /* --- prototypes --- */
  101. /* callback maintenance functions */
  102. void     g_hook_list_init        (GHookList        *hook_list,
  103.                      guint             hook_size);
  104. void     g_hook_list_clear        (GHookList        *hook_list);
  105. GHook*     g_hook_alloc            (GHookList        *hook_list);
  106. void     g_hook_free            (GHookList        *hook_list,
  107.                      GHook            *hook);
  108. GHook *     g_hook_ref            (GHookList        *hook_list,
  109.                      GHook            *hook);
  110. void     g_hook_unref            (GHookList        *hook_list,
  111.                      GHook            *hook);
  112. gboolean g_hook_destroy            (GHookList        *hook_list,
  113.                      gulong             hook_id);
  114. void     g_hook_destroy_link        (GHookList        *hook_list,
  115.                      GHook            *hook);
  116. void     g_hook_prepend            (GHookList        *hook_list,
  117.                      GHook            *hook);
  118. void     g_hook_insert_before        (GHookList        *hook_list,
  119.                      GHook            *sibling,
  120.                      GHook            *hook);
  121. void     g_hook_insert_sorted        (GHookList        *hook_list,
  122.                      GHook            *hook,
  123.                      GHookCompareFunc     func);
  124. GHook*     g_hook_get            (GHookList        *hook_list,
  125.                      gulong             hook_id);
  126. GHook*     g_hook_find            (GHookList        *hook_list,
  127.                      gboolean         need_valids,
  128.                      GHookFindFunc         func,
  129.                      gpointer         data);
  130. GHook*     g_hook_find_data        (GHookList        *hook_list,
  131.                      gboolean         need_valids,
  132.                      gpointer         data);
  133. GHook*     g_hook_find_func        (GHookList        *hook_list,
  134.                      gboolean         need_valids,
  135.                      gpointer         func);
  136. GHook*     g_hook_find_func_data        (GHookList        *hook_list,
  137.                      gboolean         need_valids,
  138.                      gpointer         func,
  139.                      gpointer         data);
  140. /* return the first valid hook, and increment its reference count */
  141. GHook*     g_hook_first_valid        (GHookList        *hook_list,
  142.                      gboolean         may_be_in_call);
  143. /* return the next valid hook with incremented reference count, and
  144.  * decrement the reference count of the original hook
  145.  */
  146. GHook*     g_hook_next_valid        (GHookList        *hook_list,
  147.                      GHook            *hook,
  148.                      gboolean         may_be_in_call);
  149. /* GHookCompareFunc implementation to insert hooks sorted by their id */
  150. gint     g_hook_compare_ids        (GHook            *new_hook,
  151.                      GHook            *sibling);
  152. /* convenience macros */
  153. #define     g_hook_append( hook_list, hook )  \
  154.      g_hook_insert_before ((hook_list), NULL, (hook))
  155. /* invoke all valid hooks with the (*GHookFunc) signature.
  156.  */
  157. void     g_hook_list_invoke        (GHookList        *hook_list,
  158.                      gboolean         may_recurse);
  159. /* invoke all valid hooks with the (*GHookCheckFunc) signature,
  160.  * and destroy the hook if FALSE is returned.
  161.  */
  162. void     g_hook_list_invoke_check    (GHookList        *hook_list,
  163.                      gboolean         may_recurse);
  164. /* invoke a marshaller on all valid hooks.
  165.  */
  166. void     g_hook_list_marshal        (GHookList        *hook_list,
  167.                      gboolean         may_recurse,
  168.                      GHookMarshaller     marshaller,
  169.                      gpointer         marshal_data);
  170. void     g_hook_list_marshal_check    (GHookList        *hook_list,
  171.                      gboolean         may_recurse,
  172.                      GHookCheckMarshaller     marshaller,
  173.                      gpointer         marshal_data);
  174.  
  175. G_END_DECLS
  176.  
  177. #endif /* __G_HOOK_H__ */
  178.  
  179.